class Movie < ActiveRecord::Base

	validates_presence_of :title, :description
	validates_uniqueness_of :title
	validates_length_of :description, :minimum => 10
	def self.ratings
		{ "G" => "G",
		  "PG" => "PG",
		  "PG-13" => "PG-13",
		  "R" => "R",
		  "NC-17" => "NC-17"
		}
	end
	
	def appropriate_for_birthdate? birthday
		if rating.eql?(Movie.ratings["G"]) || rating.eql?(Movie.ratings["PG"])
			return true
		elsif rating.eql?(Movie.ratings["PG-13"])
			return true if birthday <= Time.now - 13.years
			return false
		elsif rating.eql?(Movie.ratings["R"]) || rating.eql?(Movie.ratings["NC-17"])
			return true if birthday <= Time.now - 17.years
			return false
		end
	end
	
	def self.find_all_appropriate_for_birthdate birthday
		Movie.all.select {|x| x.appropriate_for_birthdate? birthday}
	end
	
end
